﻿@model NCP.Recruiting.WebApp.Models.CandidateListViewModel
@using NCP.Recruiting.WebApp.Models;
@using NCP.Recruiting.ApplicationServices.Shared;
@using NCP.Recruiting.WebApp.Extensions;
@{
    ViewBag.Title = "简历回收站";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    $(document).ready(function () {
        //表格隔行变色，最后一行没有边框
        $('.wrapContents table tbody tr:last-child td').css({ 'border-bottom': 'none' });
        $('.wrapContents table tbody tr:even').css({ 'background': '#f0f0f0' });
        $('.wrapContents table tbody tr:even').css({ 'background': '#fbfbfb' });

        $('.chkAll').bind('click', function () {
            $('.itemChecked').attr('checked', $(this).attr('checked'));
        });

        //批处理操作按钮点击事件
        $('#btnRecoverSelected').bind('click', function () {
            if ($('.itemChecked:checked').length == 0) {
                alert("请选择要还原的简历！");
                return false;
            }
            else {
                if (!confirm("确定要还原所选简历吗？")) {
                    return false;
                }
            }
        });
    });

    // 简历还原
    function reductionClick(id) {
        if (!confirm("确定要还原简历吗？")) {
            return false;
        }

        $.ajax({
            url: '@Url.Action("Reduction", "Candidate")',
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({
                Id: id
            }),
            success: function (result) {
                if (result) {
                    alert("还原成功！");

                    // 页面重置
                    location.href = '@Url.Action("RecoverList")';
                }
                else {
                    alert("还原失败，请重试！");
                }
            },
            error: function (result) {
                alert("还原失败，请重试！");
            }
        });
        return false;
    }

    function unreadClick(id) {
        $.ajax({
            url: '@Url.Action("SetIsReadLetter", "Candidate")',
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({
                Id: id
            }),
            success: function (result) {
                if (result) {
                    alert("设定成功！");

                    // 页面重置
                    location.href = '@Url.Action("RecoverList")';
                }
                else {
                    alert("设定失败，请重试！");
                }
            },
            error: function (result) {
                alert("设定失败，请重试！");
            }
        });
        return false;
    }
</script>
<div id="wrap">
    <div class="wrapContents">
        @using (Html.BeginForm())
        {
            <input  type="submit" value="还原所选" id="btnRecoverSelected" name="RecoverSelected"
                   style="display: none" />
            <div class="search">
                <div class="search_left">
                    <div class="caozuo">
                        @*<a href="#" onclick="$('#btnDeleteSelect').click()">删除所选</a>*@
                    </div>
                    <div class="cl">
                    </div>
                </div>
                <div class="search_right">
                    @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
                </div>
                <div class="cr">
                </div>
            </div>
            <table cellpadding="0" cellspacing="0" width="100%" id="tblJobList">
                <thead>
                    <tr>
                        <th>
                            <input class="chkAll" type="checkbox" />
                        </th>
                        <th>
                            来源
                        </th>
                        <th>
                            应聘职位
                        </th>
                        <th>
                            姓名
                        </th>
                        <th>
                            年龄
                        </th>
                        <th>
                            工作经验
                        </th>
                        <th>
                            学历
                        </th>
                        <th>
                            删除日期
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody id="tbodyJobList">
                    @foreach (var item in Model.CandidateList)
                    {
                        <tr>
                            <td>
                                @Html.HiddenFor(x => item.Id)
                                @Html.CheckBoxFor(x => item.IsChecked, new { @class = "itemChecked" })
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.SourceName)
                                @if (item.IsReadLetter)
                                {
                                    <img src="@Url.Content("~/Content/images/read.jpg")" alt="已读" />
                                }
                                else
                                {
                                    <img src="@Url.Content("~/Content/images/unread.jpg")"
                                         onclick="return unreadClick('@item.Id.ToString()');" alt="未读" />
                                }
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.JobTitle)
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.FullName)
                                @if (!string.IsNullOrEmpty(item.TagIdName))
                                {
                                    <span>@item.TagIdName</span>
                                }
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.Ages)
                                @if (item.Gender == 1)
                                { <img src="@Url.Content("~/Content/images/male.jpg")" alt="男" />}
                                else
                                { <img src="@Url.Content("~/Content/images/female.jpg")" alt="女" />}
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.YearsOfExperienceName)
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.EducationLevelName)
                            </td>
                            <td>
                                @Html.DisplayFor(x => item.LastUpdateDateString)
                            </td>
                            <td>
                                <a href="#" onclick="return reductionClick('@item.Id.ToString()');" id="lbtnReduction">还原</a>
                            </td>
                        </tr>
                    }

                </tbody>
            </table>
            <div class="pagelists">
                <div class="pagelists_btns">
                    <div class="allCheck">
                        <input class="chkAll" type="checkbox" /><span>全选</span>
                    </div>
                    <a href="#" onclick="$('#btnRecoverSelected').click()" class="fbsx">还原所选</a>
                </div>
                <div class="search_right">
                    @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
                </div>
                <div class="cr">
                </div>
            </div>
        }
    </div>
</div>
